#include <bits/stdc++.h>
// 2025/02/05
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

int n, a[100001], b[100001], mp[100001], dp[100001];

signed main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i], mp[b[i]] = i;
    for (int i = 0; i < n; i++)
        a[i] = mp[a[i]];
    memset(dp, 0x1f, sizeof(dp));
    int mx = dp[0];
    for (int i = 0; i < n; i++)
        *upper_bound(dp, dp + n, a[i]) = a[i];
    int ans = 0;
    while (dp[ans] != mx)
        ++ans;
    cout << ans;
    return 0;
}